function send_request(host) {
  // var xmlhttp = null;
  // if (window.XMLHttpRequest) {
  //   xmlhttp = new XMLHttpRequest();
  // }
  // else if (window.ActiveXObject) {
  //   xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
  // }
  // if (xmlhttp != null) {
  //   xmlhttp.open("GET", host, false);
  //   xmlhttp.send(null);
  //   return xmlhttp.responseText
  // }
  // else {
  //   alert("Your browser does not support XMLHTTP.");
  // }
  //
  // let self = this;


};


function get_signature(host) {

  var body = send_request(host)
  var obj = eval("(" + body + ")");
  return obj['data'];

};

function uuid() {

  function S4() {
    return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
  }
  return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());

}

function get_suffix(filename) {
  var pos = filename.lastIndexOf('.');
  var suffix = '';
  if (pos != -1) {
    suffix = filename.substring(pos)
  }
  return suffix;
}

function get_uploaded_object_name(dir, filename) {
  var suffix = get_suffix(filename);
  return dir + uuid() + suffix;
}


function get_upload_param(signData, filename) {
  // var signData = get_signature(host);
  var object_name = get_uploaded_object_name(signData['dir'],filename);
  var multipart_params = {
    // 'key': object_name,
    'key': filename,  //设置objectKey的值
    'filename': 'jstn-file/' + filename,  //设置上传到哪一个的文件夹
    'policy': signData['policy'],
    'OSSAccessKeyId': signData['accessid'],
    'success_action_status': '200', //让服务端返回200,不然，默认会返回204
    'callback': signData['callback'],
    'signature': signData['signature']
  };
  return {
    'url': signData['host'],
    'multipart_params': multipart_params
  }
}

export {
  get_upload_param
}
